package org.finesys.common.log.trace.interceptor.gateway;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import reactor.core.publisher.Operators;

/**
 * gateway 链路追踪注入bean对象
 * 因为gateway用的是reactor,需要处理
 */
public class LogHooks {
    private static final String KEY = "logMDC";

    @PostConstruct
    public void setHook() {
        reactor.core.publisher.Hooks.onEachOperator(KEY, Operators.lift(((scannable, coreSubscriber) -> {
            return new MDCSubscriber<>(coreSubscriber);
        })));
    }

    @PreDestroy
    public void resetHook() {
        reactor.core.publisher.Hooks.resetOnEachOperator(KEY);
    }
}
